'''
Created on 2012. 2. 19.

@author: weonseoggim
'''
import cgi
import os

from google.appengine.api import images
from google.appengine.api import users
from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from com.crayon.product.ProductSharingBaseHandler import ProuctSharingBaseHandler
import wsgiref.handlers

from com.crayon.data.DataStore import Album

class ProductUploadHandler(ProuctSharingBaseHandler):
    '''
    classdocs
    '''
    def get(self,album_key):
        album = db.get(album_key)
        self.render_to_response('product.html',{'album_key':album.key(),'album_name':album.name})
        
    def post(self,album_key):
        
        album = db.get(album_key)
        if album is None:
            self.error(400)
            self.response.out.write('Countn\t find specified album')
        title = cgi.escape(self.request.get('title'))
        caption = cgi.escape(self.request.get('caption'))
        tags = cgi.escape(self.request.get('tags')).split(',')
        tags = [tag.strip() for tag in tags]
        # Get the actual data for the picture
        img_data = self.request.POST.get('picfile').file.read()
    
        self.response.out.write('file upload ok')
        self.response.out.write('file size ', img_data.size())
            
            
    def __init__(self,param=None):
        '''
        Constructor
        '''
        